//
//  GameViewModel.swift
//  swiftDemo
//
//  Created by Gerry on 2022/1/7.
//

import UIKit
import Alamofire

let kMaxCount : Int =  40;

class GameViewModel: NSObject {
    
    lazy var gameModels : Array<GameModel> = Array<GameModel>()
    
    func requestData( responseCallback : @escaping (_ : Bool, _ : String) -> Void ) {
        Network.request(type: .GET, urlString:kGameDetailUrl, parameters: nil) { result, isSuccess in
            
            guard let ret = result as? [[String : AnyObject]] else {
                responseCallback(false, "error")
                return
            }
            let m = NSArray.yy_modelArray(with: GameModel.self, json: ret)
            print(ret)
            
            let datas = m as! [GameModel]
            let count = datas.count > kMaxCount ? kMaxCount :  datas.count;
//            for i in (0...count) {
//                self.gameModels.append(datas[i])
//            }
            self.gameModels = Array(datas[0...count])
            
            
            responseCallback(isSuccess, "ok")
        }
    }
}
